{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n",
      "/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
      "  return f(*args, **kwds)\n",
      "/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
      "  return f(*args, **kwds)\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"-1\"\n",
    "from tensorflow.keras.models import load_model\n",
    "from tensorflow.keras.datasets import mnist\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "(X_train, _), (X_test, y_test) = mnist.load_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.6/dist-packages/keras/engine/saving.py:269: UserWarning: No training configuration found in save file: the model was *not* compiled. Compile it manually.\n",
      "  warnings.warn('No training configuration found in save file: '\n"
     ]
    }
   ],
   "source": [
    "encoder = load_model('auto-encoder.h5')\n",
    "decoder = load_model('auto-decoder.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.         8.899152   6.920689   2.8540618  0.         3.9087083\n",
      "  5.929813  16.855928   0.         6.8242755] 0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f47bc0420f0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAADHCAYAAAAJSqg8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAL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ZFIqKCLiESiwe1zS2wjgBXJ50cnX8dGx9V8PtGMr32gb2fhfWqqWI8tC8dVUN+u6ErRj70wOd/MhjTLi5eRjqtli/l9ivXYYjouXXIREYmECrqISCSas6BPbMbXLicdV8sW8/sU67FFc1zNdg1dRERKS5dcREQiUfGCTvJskn8iWUtyXKVfv5SSGwivJ7koL9aZ5PMk/5x8dG8wXM1I9ib5Esl3Sb5D8rtJPPPHVk6x9G316+wd2wEVLegkawDcA+BLAI4DcAnJ4yrZhhKbDODserFxAF40swEAXky+zpq9AL5nZscBGAbgW8nPKYZjK4vI+vZkqF9nUqXP0IcCqDWzZWa2G8BjAM6rcBtKxsxeAbC5Xvg8AFOSz6cAOL+ijSoBM6szszeTz7cBWAygJyI4tjKKpm+rX2fv2A6odEHvCWBV3terk1hMuubdf3ItgK7N2ZhiJXe9HwxgLiI7thKLvW9H9bOPtV9rULSMLDeFKLPTiEi2B/AkgGvNbGv+97J+bNJ0Wf/Zx9yvK13Q1wDonfd1ryQWk3UkuwNA8nF9M7enSUi2Qq7TTzWzp5JwFMdWJrH37Sh+9rH360oX9HkABpDsS7I1gNEAple4DeU2HcDlyeeXA3imGdvSJCQJ4EEAi83sjrxvZf7Yyij2vp35n31L6NcVX1hE8ssA7gRQA+AhM7ulog0oIZKPAjgTud3a1gG4CcDTAKYBOBa53fcuMrP6A0xVjeTpAP4IYCGA/Ul4PHLXGzN9bOUUS99Wv87esR2glaIiIpHQoKiISCRU0EVEIqGCLiISCRV0EZFIqKCLiERCBV1EJBIq6CIikVBBFxGJxP8DWdRwepKc/XYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "index = 10\n",
    "original = X_test[index].astype(\"float32\") / 255.\n",
    "encoding = encoder.predict(np.array([original]))[0]\n",
    "#encoding[0] = 0\n",
    "#encoding[1] = -100\n",
    "print(encoding, y_test[index])\n",
    "plt.subplot(1,2,1)\n",
    "plt.title(\"predicted\")\n",
    "plt.imshow(decoder.predict(np.array([encoding]))[0], cmap='gray')\n",
    "plt.subplot(1,2,2)\n",
    "plt.title(\"original\")\n",
    "plt.imshow(original, cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
